package com.aweqy.porcelain.controller;

import com.aweqy.porcelain.common.BaseResponse;
import com.aweqy.porcelain.common.ResultUtils;
import com.aweqy.porcelain.entity.Region;
import com.aweqy.porcelain.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地区信息控制器
 */
@Api(tags = "地区信息管理")
@RestController
@RequestMapping("/region")
@CrossOrigin(origins = "*")
public class RegionController {
    
    @Autowired
    private RegionService regionService;
    
    @ApiOperation("获取所有地区信息")
    @GetMapping("/list")
    public BaseResponse<List<Region>> getAllRegions() {
        List<Region> regions = regionService.getAllRegions();
        return ResultUtils.success(regions);
    }
    
    @ApiOperation("根据地区ID获取地区详情")
    @GetMapping("/{regionId}")
    public BaseResponse<?> getRegionById(
            @ApiParam("地区ID") @PathVariable Integer regionId) {
        Region region = regionService.getRegionById(regionId);
        if (region == null) {
            return ResultUtils.error(404, "地区不存在");
        }
        return ResultUtils.success(region);
    }
    
    @ApiOperation("根据地理分区获取地区列表")
    @GetMapping("/geo/{geoArea}")
    public BaseResponse<List<Region>> getRegionsByGeoArea(
            @ApiParam("地理分区") @PathVariable String geoArea) {
        List<Region> regions = regionService.getRegionsByGeoArea(geoArea);
        return ResultUtils.success(regions);
    }
} 